import com.google.openrtb.OpenRtb;
import com.google.openrtb.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;


/**
 * Created by liyuhang on 2017-9-2.
 */
public class Main {
  public static void main(String[] args) throws Exception{

    // test proto
    Test.Test1 test1 = Test.Test1.newBuilder().setTest1("你好世界").build();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    test1.writeTo(os);

    Test.Test1 test2 = Test.Test1.parseFrom(new ByteArrayInputStream(os.toByteArray()));
    System.out.println(test2.getTest1());

    // test wk
    // test bidrequest
    // 造假，wk会向我方发来bidrequest请求，反序列化后是这样的一个对象
    OpenRtb.BidRequest bid = OpenRtb.BidRequest.newBuilder()
            .setId("1234534625254")
            .setAt(OpenRtb.BidRequest.AuctionType.SECOND_PRICE)
            .setTmax(120)
            .addImp(OpenRtb.BidRequest.Imp.newBuilder()
                    .setId("1")
                    .setBanner(OpenRtb.BidRequest.Imp.Banner.newBuilder()
                            .setW(300)
                            .setH(250)
                            .setPos(OpenRtb.BidRequest.Imp.AdPosition.ABOVE_THE_FOLD)
                            .addBattr(OpenRtb.CreativeAttribute.USER_INTERACTIVE)))
            .addBadv("company1.com")
            .addBadv("company2.com")
            .setSite(OpenRtb.BidRequest.Site.newBuilder()
                    .setId("234563")
                    .setName("Site ABCD")
                    .setDomain("siteabcd.com")
                    .addAllCat(Arrays.asList("IAB2-1", "IAB2-2"))
                    .setPrivacypolicy(true)
                    .setPage("http://siteabcd.com/page.htm")
                    .setRef("http://referringsite.com/referringpage.htm")
                    .setPublisher(OpenRtb.BidRequest.Publisher.newBuilder()
                            .setId("pub12345")
                            .setName("Publisher A"))
                    .setContent(OpenRtb.BidRequest.Content.newBuilder()
                            .setKeywords("keyword a,keyword b,keyword c")))
            .setDevice(OpenRtb.BidRequest.Device.newBuilder()
                    .setIp("64.124.253.1")
                    .setUa("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.16)")
                    .setOs("OS X")
                    .setFlashver("10.1")
                    .setJs(true))
            .setUser(OpenRtb.BidRequest.User.newBuilder()
                    .setId("45asdf987656789adfad4678rew656789")
                    .setBuyeruid("5df678asd8987656asdf78987654"))
            .build();

    // 我方拿到这个对象，给对方返回bidResponse
    OpenRtb.BidResponse res = OpenRtb.BidResponse.newBuilder().
            setId("1234567890")
            .addSeatbid(OpenRtb.BidResponse.SeatBid.newBuilder()
                    .addBid(OpenRtb.BidResponse.SeatBid.Bid.newBuilder()
                            .setId("1")
                            .setImpid("102")
                            .setPrice(9.43)
                            .setAdid("314")
                            .setNurl("http://adserver.com/winnotice?impid=102")
                            .setAdm(
                                    "%3C!DOCTYPE%20html%20PUBLIC%20%5C%22-"
                                            + "%2F%2FW3C%2F%2FDTD%20XHTML%201.0%20Transitional%2F%2FEN%5C%22%20%5C%22htt"
                                            + "p%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-"
                                            + "transitional.dtd%5C%22%3E%3Chtml%20xmlns%3D%5C%22http%3A%2F%2Fwww.w3.org%2F1"
                                            + "999%2Fxhtml%5C%22%20xml%3Alang%3D%5C%22en%5C%22%20lang%3D%5C%22en%5C%22"
                                            + "%3E...%3C%2Fhtml%3E")
                            .addAdomain("advertiserdomain.com")
                            .setIurl("http://adserver.com/pathtosampleimage")
                            .setCid("campaign111")
                            .setCrid("creative112")
                            .addAllAttr(Arrays.asList(OpenRtb.CreativeAttribute.ANNOYING, OpenRtb.CreativeAttribute.AUDIO_AUTO_PLAY)))
                    .setSeat("512"))
            .setBidid("abc1123")
            .setCur("USD")
            .build();

    //然后序列化后发出去

    // 测试竞价成功
    
  }
}
